<?php

/**
 * 返回数据格式化
 * @param string $msg
 * @param string $code
 * @param string $url
 * @param string $data
 * @param int $wait
 * @return array
 */
function info($msg = '', $code = '', $url = '',  $data = '', $wait = 3 )
{
	if (is_numeric($msg)) {
        $code = $msg;
        $msg  = '';
    }


    if (is_null($url) && isset($_SERVER["HTTP_REFERER"])) {
        $url = $_SERVER["HTTP_REFERER"];
    } elseif ('' !== $url) {
        $url = preg_match('/^(https?:|\/)/', $url) ? $url : Url::build($url);
        
    }
	$result = [
        'code' => $code,
        'msg'  => $msg,
        'data' => $data,
        'url'  => $url,
        'wait' => $wait,
	];
	return $result;
}


/**
 * 获取匹配金额后的利率及金额
 * @param $member
 * @return array|float|int
 */
function get_release_rate($member){

    $rate = intval(($member-0.01)/10000)*0.005+0.01;

    if($rate > 1 || $member == 0.01){
        $rate = 1;
    }
    $money = round($member*$rate,2);

    if($member < $money || $money == 0){
        $num = $member;
    }else{
        $num = $money;
    }

    return ['rate'=>$rate,'num'=>$num];
}

/**
 * 获取用户账号
 * @param $value
 * @param $type
 * @return array|float|int
 */
function get_value_username($value,$type = 'id'){
    $res = db('user')->where($type,$value)->find();

    return $res['username'];
}

/**
 * 获取图片地址
 * @param $id
 * @return string
 */
function getImgUrl($id){
    $res = db('admin_attachment')->where('id',$id)->find();

    return 'http://project.tmbc.com/'.$res['path'];
}

?>